#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2020 crane <crane@crane-pc>
#
# Distributed under terms of the MIT license.

"""

"""

class Solution:
    def numWaterBottles_slow(self, numBottles: int, numExchange: int) -> int:
        sum = numBottles

        while numBottles >= numExchange:
            nextBottles = numBottles // numExchange
            numBottles  = numBottles % numExchange + nextBottles

            sum += nextBottles

        return sum


    def numWaterBottles2(self, numBottles: int, numExchange: int) -> int:
        exchange = numBottles // (numExchange-1)
        remain = (numBottles-1) % (numExchange-1)

        if remain == 0:
            exchange -= 1

        return numBottles + exchange


    def numWaterBottles(self, numBottles: int, numExchange: int) -> int:
        exchange = (numBottles-1) // (numExchange-1)

        return numBottles + exchange



def test():
    s = Solution()
    ret = s.numWaterBottles(16, 4)
    print(ret)

    ret = s.numWaterBottles(15, 4)
    print(ret)

    ret = s.numWaterBottles(9, 3)
    print(ret)

    ret = s.numWaterBottles(5, 5)
    print(ret)

    ret = s.numWaterBottles(2, 3)
    print(ret)

def main():
    print("start main")
    test()

if __name__ == "__main__":
    main()
